package com.yuan.algorithms.arithmetic_1;

import java.util.Scanner;

public class 递归_求n个元素的全排列 {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		while (sc.hasNext()) {
			String N = sc.next();
			char[] data = N.toCharArray();
			f(data, 0);
		}
	}

	public static void f(char[] data, int k) {
		if (k == data.length) {
			for (int i = 0; i < data.length; i++) {
				System.out.print(data[i]);
			}
			System.out.println();
			return;
		}
		for (int i = k; i < data.length; i++) {
			{//交换位置
				char temp = data[i];
				data[i] = data[k];
				data[k] = temp;
			}
			f(data, k + 1);//递归
			{//回溯(还原)
				char temp = data[i];
				data[i] = data[k];
				data[k] = temp;
			}
		}
	}
}
